package com.rmi;

/**
 * Setup.java
 * 	a class dedicated to setup ActivatableHelloImpl class
 * @author Yoon Kyung Koo (yoonforh@moon.daewoo.co.kr)
 * @version 1.0 1999/05/09
 */

import java.rmi.*;
import java.rmi.activation.*;
import java.util.Properties;

/**
 * Setup class
 */
class Setup {
	public static void main(String args[]) {
		try {
			// first set security manager
			System.setSecurityManager(new RMISecurityManager());
			// create group with specified security policy
			Properties properties = new Properties();
			properties.put("java.security.policy",
				"G:\\study\\olcWorkExerciseCode\\ee\\src\\com\\rmi\\server.policy");
//		"C:\\javaworks\\rmi\\hello\\actserver\\server.policy");
		//	G:\study\olcWorkExerciseCode\ee\src\com\rmi\Setup.java
			ActivationGroupDesc actGroup =
				new ActivationGroupDesc(properties, 
				(ActivationGroupDesc.CommandEnvironment) null);
			// register group and get id
			ActivationGroupID groupID =
				ActivationGroup.getSystem().registerGroup(actGroup);
			// create group explicitly
			ActivationGroup.createGroup(groupID, actGroup, 0);
			// create activation descriptor
			ActivationDesc desc = new ActivationDesc
				("ActivatableHelloImpl",
				"file:C:\\javaworks\\rmi\\hello\\actserver\\",
				(MarshalledObject) null);
			// register desc
			Hello hello = (Hello) Activatable.register(desc);
			System.out.println("Registered and got stub");
			// bind stub
			Naming.rebind("HelloServer", hello);
			System.out.println("Successfully bound");
			// explicitly exit
			System.exit(0);
		} catch (Exception e) {
			System.err.println("Error:"+e.getMessage());
			e.printStackTrace();
		}
	}
}